<?php
class CFactory
{
	static public function get( $className, $args = null ) 
	{
		// Check $className
		if(!is_string($className)) throw new Exception("No valid class name.");
		
		// Split the className to get the packages
		$package = explode("::", $className);
		
		// Path to the class
		$filepath = "class/";
		
		// Real classname (e.g. CFoo(); )
		$filename = array_pop($package);
		$realClassName = "C" . ucfirst( $filename );
		
		// Add the packages to the absolute path
		foreach($package as $p)
			$filepath.= $p."/";
			
		// Add filename to the absolute path
		$filepath.= "class." . $filename . ".php";
		
		// Check filepath
		if(!file_exists($filepath)) throw new Exception("A class with the given name doesn't exist.");
		
		// Require class
		require_once($filepath);
		
		// Return object
		return new $realClassName($args);
		
	}
}
?>